<?php
defined('IN_XLP') or exit('Access Denied');
$Document = array(
    'pageid'   => 'task-addposter', //页面标示
    'pagename' => '添加任务发布人', //当前页面名称
    'mycss'    => array(), //加载的css样式表
    'myjs'     => array(), //加载的js脚本
    'footerjs' => array(),
    'head'     => true, //加载头部文件
);
include getTpl('header', 'public');
?>
<style>
label{cursor:pointer;font-weight:normal}
.red{color:red;}
.pt7{padding-top:7px;}
.w70{width:70px;display:inline;}
.w100{width:100px;display:inline;}
</style>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
<section id="content">
    <section class="main padder">
        <div class="clearfix">
            <h4><i class="fa fa-edit"></i>新增任务发布人</h4>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <div class="panel-body">
                        <form class="form-horizontal" id="posterAddForm" method="post" autocomplete="off">
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label">发布人手机</label>
                                <div class="col-sm-2">
                                    <input type="number" name="phone" id="phone" placeholder="手机号" class="form-control" />
                                    <input type="hidden" name="poster_uid" id="poster_uid" />
                                    <span class="help-block"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">发布人称谓</label>
                                <div class="col-sm-2">
                                    <input type="text" name="poster_name" id="poster_name" placeholder="称谓" class="form-control" />
                                </div>
                            </div>

                            <div class="form-group pt7">
                                <div class="col-sm-9 col-lg-offset-1">
                                    <div class="col-sm-1">
                                        <button type="submit" id="sub-ok" data-loading-text="正在提交..." class="btn btn-primary">保存</button>
                                    </div>
                                    <button type="button" class="btn btn-white">取消</button>
                                </div>
                            </div>

                        </form>
                    </div>
                </section>
            </div>
        </div>
    </section>
</section>
<!--/ content --> 
<!--主体 结束-->
<script>
$(function(){
    $('#posterAddForm').submit(function(){
        if( $.trim($('#poster_uid').val()) == '' || $.trim($('#phone').val()) == '' ) {
            Msg.error('请输入正确的手机号码');
            resetSubmit("#sub-ok",'提交');
            return false;
        }
        if( $.trim($('#poster_name').val()) == '' ) {
            Msg.error('请输入发布人称谓');
            resetSubmit("#sub-ok",'提交');
            return false;
        }

        Msg.loading();
        $.post('<?php echo U("task/add_poster"); ?>', $(this).serialize(), function(result){
            Msg.hide();
            resetSubmit("#sub-ok",'提交');
            if(result.status == 1) {
                Msg.ok(result.info);
                self.location.href = '<?php echo U("task/poster") ?>';
            } else {
                Msg.error(result.info);
            }
        }, 'JSON');
        return false;
    });


    //获取发布人信息
    $('#phone').on('blur',function(){
        var $this = $(this);
        var phone = $.trim($this.val());
        var $help = $this.siblings('.help-block');
        if(phone=='') {
            $help.addClass('red').text('手机号码不能为空');
            return false;
        }
        $.post("<?php echo U('task/get_user') ?>", {"phone":phone}, function(result){
            if(result.status) {
                $('#poster_uid').val(result.info.uid);
                $help.removeClass('red').text('UID：'+result.info.uid+' 昵称：'+result.info.nickname+'，请核对信息是否有误');
            } else {
                $('#poster_uid').val('');
                $help.addClass('red').text(result.info);
            }
        }, 'JSON');
    });
});
</script>
<?php include getTpl('footer', 'public'); ?>